package dao

import (
	"ssims/models"
)

func GetAllStatus(status map[string]interface{}) (error, []models.Status, int64) {
	var statusData []models.Status
	page := status["page"].(int)
	pageSize := status["limit"].(int)
	searchName := status["searchName"].(string)
	var total int64
	err := db.Table("status").Select("change_no,change_situation,student_name, change_describe, update_time").Where("student_name like ? and is_del = false", searchName+"%").Order("change_no ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&statusData).Error
	return err, statusData, total
}

func DelStatus(id string) error {
	err := db.Table("status").Where("change_no = ?", id).Update("is_del", true).Error
	return err
}

func UpdateStatus(status models.Status) error {
	err := db.Table("status").Select("change_no", "update_time", "change_situation", "change_describe").Where("student_name = ?", status.StudentName).Updates(&status).Error
	return err
}

func AddStatus(status models.Status) error {
	err := db.Table("status").Select("student_name", "change_no", "update_time", "change_situation", "change_describe", "is_del").Create(&status).Error
	return err
}
